package br.unisinos.ubicomp.locationawaretaskmanager;

import java.util.List;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.view.Menu;
import android.view.MotionEvent;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class TaskLocationMaps extends MapActivity {

	private MapView mapView;
	private MapOverlay pinOverlay;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_task_location_maps);

		Bundle extras = getIntent().getExtras();
		GeoPoint geoPoint = null;
		if (extras != null) {
			geoPoint = new GeoPoint(extras.getInt("LATITUDE"),
					          extras.getInt("LONGITUDE") );
		}
		
		mapView = (MapView) findViewById(R.id.map_view);
		mapView.setBuiltInZoomControls(true);

		mapView.getController().setZoom(16);
		
		Drawable pin  = this.getResources().getDrawable(R.drawable.pin);
		pin.setBounds(0, 0, pin.getIntrinsicWidth(), pin.getIntrinsicHeight());
		
		//List<Overlay> mapOverlays = mapView.getOverlays();
		this.pinOverlay = new MapOverlay(pin, this, geoPoint);
		mapView.getOverlays().add(pinOverlay);
		
		mapView.getController().animateTo(this.pinOverlay.getOverlayLocation());

		//MapController mapController = mapView.getController();
		//mapController.setZoom(6);
	}

	public void setSelectedPoint(GeoPoint geoPoint) {
		int[] point = new int[] {
				geoPoint.getLatitudeE6(),
				geoPoint.getLongitudeE6() };

		Intent result = new Intent();
		result.putExtra("result", point);
		setResult(RESULT_OK, result);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_task_location_maps, menu);
		return true;
	}

	@Override
	protected boolean isRouteDisplayed() {
		return false;
	}
	
	public MapView getMapView() {
		return this.mapView;
	}

}
